package com.bruip.ssm.service.impl;

import com.bruip.ssm.mapper.EmpMapper;
import com.bruip.ssm.pojo.Emp;
import com.bruip.ssm.service.EmpService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author 王若龙
 * @CreateTime 2022-09-08 17:13
 */
@Service
@Transactional
public class EmpServiceImpl implements EmpService {

    @Autowired
    private EmpMapper empMapper;


    @Override
    public List<Emp> getAllEmployee() {
        return empMapper.getAllEmployee();
    }

    @Override
    public PageInfo<Emp> getEmployeePage(Integer pageNum) {
        //开启分页
        PageHelper.startPage(pageNum, 6);
        //查询所有员工
        List<Emp> empList = empMapper.getAllEmployee();
        //获取分页相关
        PageInfo<Emp> empPageInfo = new PageInfo<>(empList, 5);
        System.out.println(empPageInfo);
        return empPageInfo;
    }

    @Override
    public void addEmployee(Emp emp) {
        empMapper.addEmployee(emp);
    }

    @Override
    public Emp getEmployeeById(Integer empId) {
        return empMapper.getEmployeeById(empId);
    }

    @Override
    public void updateEmployee(Emp emp) {
        empMapper.updateEmployee(emp);
    }

    @Override
    public void deleteEmployee(Integer empId) {
        empMapper.deleteEmployee(empId);
    }
}
